package com.luoxc.controller;

import com.luoxc.pojo.Dept;
import com.luoxc.pojo.Result;
import com.luoxc.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 日志
@Slf4j
// 公共路径
@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 查询全部部门
     * */
    @GetMapping
    public Result list(){
        List<Dept> lists = deptService.list();
        log.info("查询全部部门数据" + lists);
        return Result.success(lists);
    }
    /**
     * param id
     * 删除部门
     * */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        deptService.delete(id);
        log.info("根据id删除部门数据:" + id);
        return Result.success();
    }
    /**
     * param id
     * 添加部门
     * */
    @PostMapping
    public Result add(@RequestBody Dept dept){
        deptService.add(dept);
        log.info("添加部门数据:");
        return Result.success();
    }
    /**
     * param id
     * 修改部门
     * */
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改部门数据" + dept);
        deptService.update(dept);
        return Result.success();
    }
}
